package com.jokey.vue.configuate;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.jokey.vue.model.RespBean;
import org.springframework.http.MediaType;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author JokeyFeng
 * @date: 2021/11/27
 * @project: vuehr
 * @package: com.jokey.vue.configuate
 * @comment: 注销登录处理器
 */
@Component
public class CustomLogoutSuccessHandler implements LogoutSuccessHandler {
	
	@Override
	public void onLogoutSuccess(HttpServletRequest request,
								HttpServletResponse response,
								Authentication authentication) throws IOException, ServletException {
		RespBean ok = RespBean.ok("注销成功！");
		response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
		PrintWriter out = response.getWriter();
		out.write(new ObjectMapper().writeValueAsString(ok));
		out.flush();
		out.close();
	}
}
